package com.ziyun.pop.rest.module.mall.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.service.common.model.PageParamDto;
import com.service.common.model.PageResult;
import com.service.ucenter.api.UserWalletService;
import com.service.ucenter.constant.UcenterResult;
import com.service.ucenter.model.wallet.ScholarshipRecordVO;
import com.service.ucenter.model.wallet.UserWalletVO;
import com.ziyun.pop.common.utils.UserUtils;

import io.renren.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@Api(value = "UserScholarshipRestApi", tags = "商城用户奖励金服务")
@RestController
@RequestMapping("popApi/mall/user/")
public class UserScholarshipRestApi {

	@Autowired
	private UserWalletService userWalletService;

	@ApiOperation(value = "查看奖励金记录", notes = "根据页面参数来显示列表")
	@ApiResponses(value = @ApiResponse(code = 200, message = "获取成功", response = ScholarshipRecordVO.class))
	@PostMapping("/listScholarshipRecord")
	public R listScholarshipRecord(@RequestBody PageParamDto pageParamDto) {
		UcenterResult<PageResult<ScholarshipRecordVO>> ucenterResult = userWalletService
				.listScholarshipRecord(UserUtils.getMallUserId(), pageParamDto);
		if (R.isError(ucenterResult.getCode())) {
			return R.error(ucenterResult.getCode(), ucenterResult.getMessage());
		}
		return R.apiOk(ucenterResult.getData());
	}

	@ApiOperation(value = "获取用户钱包金额", notes = "获取用户钱包金额")
	@ApiResponses(value = @ApiResponse(code = 200, message = "获取成功", response = UserWalletVO.class))
	@PostMapping("/getUserWallet")
	public R getUserWallet() {
		UcenterResult<UserWalletVO> ucenterResult = userWalletService.getUserWallet(UserUtils.getMallUserId());
		if (R.isError(ucenterResult.getCode())) {
			return R.error(ucenterResult.getCode(), ucenterResult.getMessage());
		}
		return R.apiOk(ucenterResult.getData());
	}

	@ApiOperation(value = " 验证是否设置 预存款（支付）密码")
	@ApiResponses(value = @ApiResponse(code = 200, message = "预存款密码已设置"))
	@GetMapping("/isSetPass")
	public R isSetPass() {
		UcenterResult<Boolean> ucenterResult = userWalletService.isSetPass(UserUtils.getMallUserId());
		if (R.isError(ucenterResult.getCode())) {
			return R.error(ucenterResult.getCode(), ucenterResult.getMessage());
		}
		return R.apiOk(ucenterResult.getData());
	}

}
